<?php

require_once dirname(__DIR__) . "/phonecode/SignatureHelper.php";
use Aliyun\DySDKLite\SignatureHelper;


defined('IN_IA') or exit ('Access Denied');
class send extends WeModuleSite{
    function sendcode($phone,$aaa,$setphone) {
        $params = array ();
        $security = false;
        $accessKeyId = $setphone['accessKeyId'];
        $accessKeySecret = $setphone['accessKeySecret'];
        $params["PhoneNumbers"] = $phone;
        $params["SignName"] = $setphone['SignName'];
        $params["TemplateCode"] = $setphone['TemplateCode'];
        if(is_array($aaa)){
            if($aaa['type']== 1){
                $params['TemplateParam'] = Array (
                    'name'  => $aaa['name'],
                    "title" => $aaa['title'],
                    'time'  => $aaa['time']
                );
            }elseif ($aaa['type'] == 2){
                $params['TemplateParam'] = Array (
                    'name'  => $aaa['name'],
                    "title" => $aaa['title'],
                );
            }

        }else{
            $params['TemplateParam'] = Array (
                'code'  => $aaa,
            );
        }

        $params['OutId'] = "12345";
        $params['SmsUpExtendCode'] = "1234567";
        if(!empty($params["TemplateParam"]) && is_array($params["TemplateParam"])) {
            $params["TemplateParam"] = json_encode($params["TemplateParam"], JSON_UNESCAPED_UNICODE);
        }

        $helper = new SignatureHelper();
        $content = $helper->request(
            $accessKeyId,
            $accessKeySecret,
            "dysmsapi.aliyuncs.com",
            array_merge($params, array(
                "RegionId" => "cn-hangzhou",
                "Action" => "SendSms",
                "Version" => "2017-05-25",
            )),
            $security
        );
        return $content;
    }
}




